import java.util.HashMap;
import java.util.Map;

/**
 * This class will hold the user accounts
 * @author Leshi
 *
 */
public class Accounts {
	/**
	 * the account holder that holds all user login information
	 */
	private static Map<String, String> accounts;
	/**
	 * construct the accounts holder
	 */
	public Accounts(){
		accounts = new HashMap<String, String>();
	}
	/**
	 * Creates a new user
	 * if the username already exist, the user will not be created
	 * @param username
	 * @param password
	 * @return
	 */
	public boolean createUser(String username, String password){
		if (checkExistingUser(username)){
			//notify the user here
			return false;
		}else{
			accounts.put(username, password);
			return true;
		}
	}
	/**
	 * check whether username already exist
	 * @param newUser
	 * @return true if already exist, false otherwise
	 */
	private boolean checkExistingUser(String newUser) {
		if(accounts.containsKey(newUser)){
			return true;
		}else{
			return false;
		}
		
	}
	/**
	 * log in the user
	 * @param username
	 * @param password
	 * @return true if successful, false otherwise
	 */
	public boolean login(String username, String password){
		if (checkExistingUser(username)){
			if(accounts.get(username).equals(password)){
				return true;
			}
		}
		//notify the user of wrong login info
		return false;
	}
}
